import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

class MyRootPage extends StatefulWidget{
  MyRootPage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyRootPageState createState() => _MyRootPageState();

}

class _MyRootPageState extends State<MyRootPage> {




  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body:Container(
        color :Color(0xffeaeaea),
//        padding:EdgeInsets.only(top: 10),


        child:ListView(
            children: <Widget>[
              MineTopWidget("RootResource/images/nav_hdxx_normal.png","wang",onTap: (){

              }),




              _listViewLine, // 分割线
              MineItemWidget("lib/My/images/set_my_school.png","我的学校",onTap: (){
                print('发布记录');
              }),
              MineItemWidget("lib/My/images/set_my_class.png","我的班级",onTap: (){

              }),
              MineItemWidget("lib/My/images/set_stustate_ico.png","学生管理",onTap: (){

              }),



              _listViewLine,
              MineItemWidget("lib/My/images/set_collectView.png","我的收藏",onTap: (){

              }),
              MineItemWidget("lib/My/images/set_resourceView.png","我的资源",onTap: (){

              }),
              MineItemWidget("lib/My/images/my_ujifen.png","我的优币",onTap: (){

              }),


              _listViewLine,
              MineItemWidget("lib/My/images/set_help_feedback.png","帮助与反馈",onTap: (){

              }),

              _listViewLine,
              MineItemWidget("lib/My/images/set_SetView.png","设置",onTap: (){
                Navigator.of(context).pushNamed("settingPage",);
              }),


            ],
          ),




      )

     );
      // This trailing comma makes auto-formatting nicer for build methods.

  }
}
class MineTopWidget extends StatelessWidget {
  String imageName;
  String title;
  @required VoidCallback onTap;

  MineTopWidget(this.imageName,this.title,{this.onTap});
  @override
  Widget build(BuildContext context) {
    return Container(
        child: Column(
          children: <Widget>[
            Container(
              color: Colors.white,
              height: 80,
              child: _mineItem(imageName, title),
            ),
            Container(
              color: Color(0xffeaeaea),
              constraints: BoxConstraints.expand(height: 1.0),
            ),
          ],
        )
    );
  }

  Widget _mineItem(String imageName,String title) {
    return InkWell(
      onTap: (){
        this.onTap();
      },
      child: Row(
        children: <Widget>[
          Expanded(
            flex: 2,
            child: Container(
              padding: EdgeInsets.only(left: 16),
              child:CachedNetworkImage(
                imageUrl: "https://static001.geekbang.org/resource/image/7d/eb/7d5a36a8727ed68f241719b7768262eb.jpg",
                placeholder: (context, url) => CircularProgressIndicator(),
                errorWidget: (context, url, error) => Icon(Icons.error),

              )

            ),
          ),
          Expanded(
            flex: 7,
            child: Container(
              padding: EdgeInsets.only(left: 10),
              child: Text(
                title,
                style: TextStyle(fontSize: 16),
              ),

            ),
          ),
          Expanded(
            flex: 1,
            child: Container(
              child: Icon(
                Icons.keyboard_arrow_right,
                size: 20,
                color: Colors.grey,
              ),
            ),
          ),
        ],
      ),
    );
  }
}


class MineItemWidget extends StatelessWidget {
  String imageName;
  String title;
  @required VoidCallback onTap;

  MineItemWidget(this.imageName,this.title,{this.onTap});
  @override
  Widget build(BuildContext context) {
    return Container(
        child: Column(
          children: <Widget>[
            Container(
              color: Colors.white,
              height: 53,
              child: _mineItem(imageName, title),
            ),
            Container(
              color: Color(0xffeaeaea),
              constraints: BoxConstraints.expand(height: 1.0),
            ),
          ],
        )
    );
  }

  Widget _mineItem(String imageName,String title) {
    return InkWell(
      onTap: (){
        this.onTap();
      },
      child: Row(
        children: <Widget>[
          Expanded(
            flex: 1,
            child: Container(
              padding: EdgeInsets.only(left: 16),
              child: Image.asset(
                imageName,
                width: 30,
                height: 30,
              ),
            ),
          ),
          Expanded(
            flex: 6,
            child: Container(
              padding: EdgeInsets.only(left: 10),
              child: Text(
                title,
                style: TextStyle(fontSize: 16),
              ),

            ),
          ),
          Expanded(
            flex: 1,
            child: Container(
              child: Icon(
                Icons.keyboard_arrow_right,
                size: 20,
                color: Colors.grey,
              ),
            ),
          ),
        ],
      ),
    );
  }
}



// 分割线
Widget get _listViewLine {
  return Container(
    color: Color(0xffeaeaea),
    height: 6,
  );
}